package lanqiao.hol.control;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.lanqiao.tjut.bean.TBStudentBean;
import org.lanqiao.tjut.model.ModelFactory;
import org.lanqiao.tjut.myUtils.MyUtils;

/**
 * 添加学生信息
 */
@WebServlet("/StudentInfoAddServlet")
@MultipartConfig(maxFileSize = 8000000)
public class StudentInfoAddServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#service(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
         // 调用换行方法，将requset对象中的参数依次赋值给实体类
		TBStudentBean stuB = MyUtils.convertRequest2Bean(request, TBStudentBean.class, "uploadfiles/stuImgs/", "stuImg");
		System.out.println("stu:" + stuB.toString());
		// 调用model层进行登陆验证的业务逻辑处理
		// 获取登录用户信息
		int lststu = ModelFactory.getStudentModelInstance().saveOrUpdateStudentInfo(stuB);			// 跳转到添加成功的页面，页面跳转后的代码不会再被执行
		// 判定是否添加成功
		if (lststu > 0) {
			// 使用转发进行跳转
			request.getRequestDispatcher("WEB-INF/logined/studentInfoManager/studentInfoAjaxQueryPager.jsp").forward(request, response);
		} else {
			// 保存失败
						response.getWriter().write(
								"<script language='javascript'>alert('数据保存失败!');"
								+ "location.href='DispatchCommServlet?"
								+ "jp=WEB-INF/logined/studentInfoManager/studentInfoAdd';</script>");
		}
	}

}
